package org.ysu.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.ysu.core.BaseEntity;

import java.util.HashMap;
import java.util.Map;

public class Coding {
    public static void main(String[] args) {
        String url = "jdbc:mysql://10.25.128.145:3306/spp";
        String bathName = System.getProperty("user.dir");
        String table = "villages";
        FastAutoGenerator.create(url,"root","123456")
                .globalConfig(i -> {
                    i.author("ZhangYibo");
                    i.disableOpenDir();
                    i.outputDir(bathName + "/src/main/java");
                    i.enableSwagger();
                })
                .packageConfig(i -> {
                    Map<OutputFile,String> pathInfo = new HashMap<OutputFile,String>();
                    pathInfo.put(OutputFile.xml,"src/main/resources/org/ysu/mapper");
                    i.parent("org.ysu")
                            .pathInfo(pathInfo);
                }).strategyConfig(i -> {
                    i.addInclude(table);
                    i.entityBuilder()
                            .superClass(BaseEntity.class)
                            .addSuperEntityColumns("id")
                            .enableLombok()
                            .naming(NamingStrategy.underline_to_camel)
                            .columnNaming(NamingStrategy.underline_to_camel)
                            .controllerBuilder()
                            .enableRestStyle()
                            .serviceBuilder()
                            .formatServiceFileName("%sService");
                }).templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
